/*
 * DialogSymbolSelection.java
 *
 * Created on 2. prosinec 2007, 11:55
 */

package jgaf.automaton.pda;

import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextField;

/**
 *
 * @author  hanis
 */
public class DialogSymbolSelection extends javax.swing.JDialog implements ActionListener {
    
    private static final int butSize = 10;
    private static final char[] names = {
        AutomataConstants.ALFA_LOW,
        AutomataConstants.BETA_LOW,
        AutomataConstants.GAMMA_LOW,
        AutomataConstants.DELTA_LOW,
        AutomataConstants.EPSILON_LOW,
        AutomataConstants.DZETA_LOW,
        AutomataConstants.ETA_LOW,
        AutomataConstants.THETA_LOW,
        AutomataConstants.LOTA_LOW,
        AutomataConstants.KAPPA_LOW,
        AutomataConstants.LAMBDA_LOW,
        AutomataConstants.MY_LOW,
        AutomataConstants.NY_LOW,
        AutomataConstants.KSI_LOW,
        AutomataConstants.OMIKRON_LOW,
        AutomataConstants.PI_LOW,
        AutomataConstants.RO_LOW,
        AutomataConstants.SIGMA_LOW,
        AutomataConstants.TAU_LOW,
        AutomataConstants.YPSILON_LOW,
        AutomataConstants.FI_LOW,
        AutomataConstants.CHI_LOW,
        AutomataConstants.PSI_LOW,
        AutomataConstants.OMEGA_LOW,
        
        AutomataConstants.ALFA_UP,
        AutomataConstants.BETA_UP,
        AutomataConstants.GAMMA_UP,
        AutomataConstants.DELTA_UP,
        AutomataConstants.EPSILON_UP,
        AutomataConstants.DZETA_UP,
        AutomataConstants.ETA_UP,
        AutomataConstants.THETA_UP,
        AutomataConstants.LOTA_UP,
        AutomataConstants.KAPPA_UP,
        AutomataConstants.LAMBDA_UP,
        AutomataConstants.MY_UP,
        AutomataConstants.NY_UP,
        AutomataConstants.KSI_UP,
        AutomataConstants.OMIKRON_UP,
        AutomataConstants.PI_UP,
        AutomataConstants.RO_UP,
        AutomataConstants.SIGMA_UP,
        AutomataConstants.TAU_UP,
        AutomataConstants.YPSILON_UP,
        AutomataConstants.FI_UP,
        AutomataConstants.CHI_UP,
        AutomataConstants.PSI_UP,
        AutomataConstants.OMEGA_UP
    };
    
    
    private JButton[] buttons;
    private JTextField component;
    
    public DialogSymbolSelection(java.awt.Dialog parent, boolean modal, JTextField component) {
        super(parent, modal);
        this.component = component;
        initComponents();
        this.setLocationRelativeTo(component);
        initButtons();
        this.pack();
     //   DesignManipulation.getInstance().setDesign(this.getContentPane());
        this.setVisible(true);        
        //System.out.println(AutomataConstants.GAMMA_LOW);
    //    this.pack();
    }
    
    
    private void initButtons() {        
        this.buttons = new JButton[48];
        for (int i = 0; i < 48; i++) {
            this.buttons[i] = new JButton();
            this.buttons[i].setSize(butSize,butSize);
            this.buttons[i].setText(String.valueOf(names[i]));
            this.buttons[i].setFont(new Font("Dialog", Font.PLAIN ,12));
            this.buttons[i].setMargin(new Insets(2,2,2,2));
            this.buttons[i].setFocusPainted(false);
            this.buttons[i].addActionListener(this);
            this.buttons[i].setActionCommand(String.valueOf(i));
            panel.add(this.buttons[i]);            
        }   
        panel.repaint();
    }
    
    public void actionPerformed(ActionEvent e) {
        int pointer = Integer.parseInt(e.getActionCommand()); 
        //System.out.println(pointer);
       // System.out.println(names[pointer]);
        component.setText(String.valueOf(names[pointer]));
        this.dispose();
    }    
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        panel = new javax.swing.JPanel();
        butStornno = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(java.util.ResourceBundle.getBundle("pdasimulator/localization").getString("specialSymbols.title"));
        panel.setLayout(new java.awt.GridLayout(6, 8));

        butStornno.setText(java.util.ResourceBundle.getBundle("pdasimulator/localization").getString("freq.storno"));
        butStornno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butStornnoActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(panel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(butStornno))
                .addContainerGap(13, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(panel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 23, Short.MAX_VALUE)
                .add(butStornno))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void butStornnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butStornnoActionPerformed
        this.dispose();
    }//GEN-LAST:event_butStornnoActionPerformed
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butStornno;
    private javax.swing.JPanel panel;
    // End of variables declaration//GEN-END:variables
    
}
